<%@page pageEncoding="utf-8" %>
<html>
<head>
    <script>

        window.onload=function() {
            debugger;
            document.getElementById("name").value="12345";
        }


        let obj={
            name:null,
            sex:null,
            age:null,
            lovey:null,
            password:null
        };
        function checkFormSubmitMethod() {
            debugger;
            let userForm=document.forms["userForm"];
            console.log(userForm.name);
            obj.name= userForm["name"].value;
            obj.sex = userForm["sex"].value;
            obj.age = userForm["age"].value;
            obj.lovey = userForm["lovey"].value;
            obj.password = userForm["password"].value;

            if( obj.name == "" ||
                obj.sex == "" ||
                obj.age == "" ||
                obj.lovey == "" ||
                obj.password == "" ){
                alert("输入数据为空");
                return false;
            }else {
                document.write("提交成功");
                return true;
            }
        }

        function checkFormSubmitMethod1() {
            debugger;
            let userForm=document.forms["userForm"];
            console.log(userForm.name);
            obj.name= userForm["name"].value;
            obj.sex = userForm["sex"].value;
            obj.age = userForm["age"].value;
            obj.lovey = userForm["lovey"].value;
            obj.password = userForm["password"].value;

            if( obj.name == "" ||
                obj.sex == "" ||
                obj.age == "" ||
                obj.lovey == "" ||
                obj.password == "" ){
                alert("输入数据为空");
                return false;
            }else {
                document.write("提交成功");
                return true;
            }
        }

    </script>
</head>
<body>
    <form action="/ab/ac" method="post" name="userForm"  onsubmit="return checkFormSubmitMethod()">
        <span>姓名：</span>
        <input type="text"  id="name" value="">
        <br>
        <span>性别：</span>
        <span style="margin-left: 20px; margin-right: 10px">男</span>
        <input type='radio' name='sex' value='男' checked/>
        <span style="margin-left: 35px; margin-right: 10px">女</span>
        <input type='radio' name='sex' value='女'/>
        <br>
        <span>年龄：</span>
        <select name="age"
                style="margin-right: 10px; width: 170px">
            <option value="0-20">
                0-20
            </option>
            <option value="21-30">
                21-30
            </option>
            <option value="31-60">
                31-60
            </option>
            <option value="61-120">
                61-120
            </option>
        </select>
        <br>
        <span>爱好：</span>
        <input type="text" name="lovey" value="">
        <br>
        <span>密码：</span>
        <input type="text" name="password" value="">

        <input type="button" value="普通提交" onclick="checkFormSubmitMethod1()"/>

        <input type="submit" value="SUBMIT提交"/>
    </form>
</body>

</html>
